home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / usr_-_Usr_Files / INCLUDE / MALLOC.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  5KB  |  158 lines

  1. /* Prototypes and definition for malloc implementation.
  2.    Copyright (C) 1996, 1997 Free Software Foundation, Inc.
  3.    This file is part of the GNU C Library.
  4.  
  5.    The GNU C Library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public License as
  7.    published by the Free Software Foundation; either version 2 of the
  8.    License, or (at your option) any later version.
  9.  
  10.    The GNU C Library is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public
  16.    License along with the GNU C Library; see the file COPYING.LIB.  If not,
  17.    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18.    Boston, MA 02111-1307, USA.  */
  19.  
  20. #ifndef _MALLOC_H
  21. #define _MALLOC_H    1
  22.  
  23. #include <features.h>
  24.  
  25. #ifndef    NULL
  26. #ifdef __cplusplus
  27. #define    NULL    0
  28. #else
  29. #define    NULL    ((void *) 0)
  30. #endif
  31. #endif
  32.  
  33. #ifdef    __STDC__
  34. #include <stddef.h>
  35. #else
  36. #undef    size_t
  37. #define    size_t        unsigned int
  38. #undef    ptrdiff_t
  39. #define    ptrdiff_t    int
  40. #endif
  41.  
  42. extern int __libc_malloc_initialized;
  43.  
  44. /* For backward compatibilities and X11R5 */
  45. #if (defined(MALLOC_0_RETURNS_NULL) || defined(NO_FIX_MALLOC)) \
  46.     && !defined(__MALLOC_0_RETURNS_NULL)
  47. #define __MALLOC_0_RETURNS_NULL
  48. #endif
  49.  
  50. __BEGIN_DECLS
  51.  
  52. /* We have changed malloc () to take malloc (0). */
  53. #if 0 && defined(_STDLIB_H) && !defined(__MALLOC_0_RETURNS_NULL)
  54. /* Allocate SIZE bytes of memory.  */
  55. static void * malloc __P ((size_t __size));
  56. /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0.  */
  57. static void * calloc __P ((size_t __nmemb, size_t __size));
  58. #else
  59. /* Allocate SIZE bytes of memory.  */
  60. extern __ptr_t malloc __P ((size_t __size));
  61. /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0.  */
  62. extern __ptr_t calloc __P ((size_t __nmemb, size_t __size));
  63. #endif
  64. /* Re-allocate the previously allocated block
  65.    in __ptr_t, making the new block SIZE bytes long.  */
  66. extern __ptr_t realloc __P ((__ptr_t __ptr, size_t __size));
  67. /* Free a block allocated by `malloc', `realloc' or `calloc'.  */
  68. extern void free __P ((__ptr_t __ptr));
  69.  
  70. /* Allocate SIZE bytes allocated to ALIGNMENT bytes.  */
  71. extern __ptr_t memalign __P ((size_t __alignment, size_t __size));
  72.  
  73. /* Allocate SIZE bytes on a page boundary.  */
  74. extern __ptr_t valloc __P ((size_t __size));
  75.  
  76. /* Underlying allocation function; successive calls should
  77.    return contiguous pieces of memory.  */
  78. extern __ptr_t (*__morecore) __P ((ptrdiff_t __size));
  79.  
  80. /* Default value of `__morecore'.  */
  81. extern __ptr_t __default_morecore __P ((ptrdiff_t __size));
  82. extern __ptr_t __default_morecore_init __P ((ptrdiff_t __size));
  83.  
  84. /* Nonzero if `malloc' has been called and done its initialization.  */
  85. extern int __malloc_initialized;
  86.  
  87. /* Hooks for debugging versions.  */
  88. extern void (*__free_hook) __P ((__ptr_t __ptr));
  89. extern __ptr_t (*__malloc_hook) __P ((size_t __size));
  90. extern __ptr_t (*__realloc_hook) __P ((__ptr_t __ptr, size_t __size));
  91.  
  92. /* Activate a standard collection of debugging hooks.  */
  93. extern void mcheck __P ((void (*__func)(void)));
  94.  
  95. /* Activate a standard collection of tracing hooks.  */
  96. extern void mtrace __P ((void));
  97.  
  98. /* Statistics available to the user.  */
  99. struct mstats
  100.   {
  101.     size_t bytes_total;        /* Total size of the heap. */
  102.     size_t chunks_used;        /* Chunks allocated by the user. */
  103.     size_t bytes_used;        /* Byte total of user-allocated chunks. */
  104.     size_t chunks_free;        /* Chunks in the free list. */
  105.     size_t bytes_free;        /* Byte total of chunks in the free list. */
  106.   };
  107.  
  108. /* Pick up the current statistics. */
  109. extern struct mstats mstats __P ((void));
  110.  
  111. /* These are for malloc from Doug Lea, dl@cs.oswego.edu. */
  112. extern int malloc_trim __P((size_t __pad));
  113. extern size_t malloc_usable_size __P((void * __mem));
  114. extern void malloc_stats __P((void));
  115.  
  116. struct mallinfo
  117. {
  118.   int arena;    /* total space allocated from system */
  119.   int ordblks;  /* number of non-inuse chunks */
  120.   int smblks;   /* unused -- always zero */
  121.   int hblks;    /* number of mmapped regions */
  122.   int hblkhd;   /* total space in mmapped regions */
  123.   int usmblks;  /* unused -- always zero */
  124.   int fsmblks;  /* unused -- always zero */
  125.   int uordblks; /* total allocated space */
  126.   int fordblks; /* total non-inuse space */
  127.   int keepcost; /* top-most, releasable (via malloc_trim) space */
  128. };
  129.  
  130. extern struct mallinfo mallinfo __P((void));
  131.  
  132. extern int mallopt __P((int __param, int __val));
  133. /* Valid param_number values. */
  134. #ifndef M_TRIM_THRESHOLD
  135. #define M_TRIM_THRESHOLD    -1
  136. #endif
  137. #ifndef M_TOP_PAD
  138. #define M_TOP_PAD        -2
  139. #endif
  140. #ifndef M_MMAP_THRESHOLD
  141. #define M_MMAP_THRESHOLD    -3
  142. #endif
  143. #ifndef M_MMAP_MAX
  144. #define M_MMAP_MAX        -4
  145. #endif
  146.      
  147. /* Record the state of all malloc variables in an opaque data structure. */
  148. extern void * malloc_get_state __P ((void));
  149.  
  150. /* Restore the state of all malloc variables from data obtained with
  151.    malloc_get_state(). */
  152. extern int malloc_set_state __P ((void * __ptr));
  153.  
  154. __END_DECLS
  155.  
  156.  
  157. #endif /* malloc.h  */
  158.